export const validateFn = async () => {
  const validteArrary = [
    { isValidate: this.existsSourceTable.kafkaTopic, errMsg: '对应topic：bc-库名-表名 不存在,请确认' },
    { isValidate: this.form.job.name, errMsg: '任务名称必填', ref: 'jobNameInput' },
    { isValidate: this.form.reader.dsCosmosName, errMsg: '源表库名必填', ref: 'readerDbSelect' },
    { isValidate: this.form.reader.hoodiePrimaryKeys, errMsg: '主键必填', ref: 'readerPrimaryKeyInput' },
    { isValidate: this.validateTableItem(), errMsg: '源表字段至少填写一项' },
  ];
  let validate = true;
  for (let i = 0, len = validteArrary.length; i < len; i += 1) {
    if (!validate) {
      break;
    }

    const item = validteArrary[i];

    if (!item.isValidate || item.isValidate.length === 0) {
      this.$message.warning(item.errMsg);
      if (this.$refs[item.ref]) {
        this.$refs[item.ref].focus();
      }
      validate = false;
    }
  }

  if (!this.$refs.JobQueueForm.validate()) {
    validate = false;
  }

  const params = {
    jobId: this.form.job.id,
    dbName: this.form.writer.dbName,
    tableName: this.form.writer.table,
  };
  const queryString = objectToQuery(params);
  const { body: { data } } = await this.$http.get(`/offline-scheduling/api/v2/job/validHudiTable${queryString}`);
  if (!data) {
    this.$message.warning('目标表名重复,请修改!');
    validate = false;
  }

  return validate;
}